package test.examation;

import dataS.hashThree.Linked;

import java.util.LinkedList;
import java.util.Scanner;

public class 奇安信 {
    static int count;
    //奇安信笔试题
    public static void main(String[] args) {

        /*int coins[]={1,2,5};
        System.out.println(change(coins,5));*/


//        System.out.println(m2());
        int nums[]={1,1,2};
        int flag[]=new int [nums.length];
        LinkedList<Integer> track=new LinkedList<>();
        backtrack(nums,flag,track);
        System.out.println(count);

    }
    //求数组的排列中的亲7数
    public static void backtrack(int nums[], int flag[], LinkedList<Integer>track){
        if(track.size()==nums.length&&check(track)){
            count++;
        }
        for(int i=0;i<nums.length;i++){
            if(flag[i]==1) continue;

            track.add(nums[i]);
            flag[i]=1;
            backtrack(nums,flag,track);
            track.removeLast();
            flag[i]=0;
        }
    }
    public static boolean check(LinkedList<Integer> list){//写法

        StringBuilder s = new StringBuilder();
        for (int i : list) {
            s.append(i);
        }
        int n = Integer.parseInt(s.toString());
        return n % 7 == 0;
    }

    private static int m2() {//求可以购买到的最大价值
        Scanner sc=new Scanner(System.in);
        int buget=sc.nextInt();
        int n=sc.nextInt();
        int price[]=new int[n];
        int value[]=new int[n];
        for(int i=0;i<n;i++){
            price[i]=sc.nextInt();
            value[i]=sc.nextInt();
        }
        int dp[]=new int[buget+1];//dp[i]代表使用i钱可以购买到的最大价值，每种商品数量不限
        dp[0]=0;
        for(int i=1;i<=buget;i++){
            for(int j=0;j<n;j++){
                if(i>=price[j])
                    dp[i]=Math.max(dp[i],dp[i-price[j]]+value[j]);
            }
        }
        return dp[buget];
    }

    public static int change(int coins[],int money){
        int dp[]=new int[money+1];
        dp[0]=1;//此处是1
        for(int coin:coins){
            for(int j=1;j<=money;j++){
                if(j>=coin)
                    dp[j]+=dp[j-coin];
            }
        }
        return dp[money];
    }
}
